typedef struct stack
{
	int* arr;
	int top;
	int capcity;
}ST;
bool StackEmpty(ST* p);
void StackInit(ST* p)
{
	p->arr = (int*)malloc(sizeof(int) * 4);
	p->capcity = 4;
	p->top = 0;
}
void StackPush(ST* p, int x)
{
	if (p->top == p->capcity)
	{
		int* temp = (int*)realloc(p->arr, sizeof(int) * (p->capcity * 2));
		if (temp != NULL)
		{
			p->arr = temp;
			p->capcity *= 2;
		}
		p->arr[p->top] = x;
		p->top++;
	}
	else
	{
		p->arr[p->top] = x;
		p->top++;
	}
}
void StackPop(ST* p)
{
	assert(p);
	assert(p->top > 0);
	if (StackEmpty(p) == true)
	{
		printf("栈为空");
		return;
	}
	else
	{
		p->top--;
	}
}
void StackDestory(ST* p)
{
	if (StackEmpty(p) == true )
	{
		printf("栈为空");
		return;
	}
	else
	{
		free(p->arr);
		p->arr = NULL;
		p->top = 0;
		p->capcity = 0;
	}
}
int StackTop(ST* p)
{
	assert(p);
	assert(p->top > 0);
	return p->arr[p->top-1];
}
bool StackEmpty(ST* p)
{
	assert(p);
	return p->top == 0;
}
void StackShow(ST p)
{
	if (StackEmpty(&p) == 1)
	{
		printf("栈为空");
		return;
	}
	else
	{
		for (int i = p.top-1; i >=0; i--)
		{
			printf("%d ", p.arr[i]);
		}
	}
}
int StackSize(ST* p)
{
	assert(p);
	return p->top;
}
typedef struct {
    ST pushst;
    ST popst;
} MyQueue;

int myQueuePeek(MyQueue* obj);
MyQueue* myQueueCreate() 
{
    MyQueue* temp = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&temp->pushst);
    StackInit(&temp->popst);

    return temp;
}

void myQueuePush(MyQueue* obj, int x) 
{
    assert(obj);
    StackPush(&obj->pushst,x);
}

int myQueuePop(MyQueue* obj) 
{
    assert(obj);
    int temp = myQueuePeek(obj);
    StackPop(&obj->popst);
    return temp;
}

int myQueuePeek(MyQueue* obj) 
{
    assert(obj);
    if(StackEmpty(&obj->popst))
    {
        while(!StackEmpty(&obj->pushst))
        {
            StackPush(&obj->popst,StackTop(&obj->pushst));
            StackPop(&obj->pushst);
        }
    }

    return  StackTop(&obj->popst);
}

bool myQueueEmpty(MyQueue* obj) 
{
    assert(obj);

    return StackEmpty(&obj->popst) && StackEmpty(&obj->pushst);
}

void myQueueFree(MyQueue* obj) 
{
    assert(obj);

    StackDestory(&obj->popst);
    StackDestory(&obj->pushst);

    free(obj);
}

/**
 * Your MyQueue struct will be instantiated and called as such:
 * MyQueue* obj = myQueueCreate();
 * myQueuePush(obj, x);
 
 * int param_2 = myQueuePop(obj);
 
 * int param_3 = myQueuePeek(obj);
 
 * bool param_4 = myQueueEmpty(obj);
 
 * myQueueFree(obj);
*/